package com.bwie.doctorclient.controller;

import com.bwie.common.core.domain.Result;
import com.bwie.doctorclient.domain.dto.AddCommonlyDosageDTO;
import com.bwie.doctorclient.domain.dto.AddCommonlyPrescriptionDTO;
import com.bwie.doctorclient.domain.po.CommonlyDosagePO;
import com.bwie.doctorclient.domain.po.CommonlyPrescriptionPO;
import com.bwie.doctorclient.domain.vo.CommonlyPrescriptionVO;
import com.bwie.doctorclient.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prescription")
public class PrescriptionController {
    @Autowired
    private PrescriptionService prescriptionService;

    /**
     * 获取常用处方列表
     * @return
     */
    @GetMapping("/getCommonlyPrescription")
    public Result getCommonlyPrescription(){
        List<CommonlyPrescriptionVO> list = prescriptionService.getCommonlyPrescription();
        return Result.success(list);
    }

    /**
     * 删除常用处方
     * @param commonlyPrescriptionId
     * @return
     */
    @DeleteMapping("/delCommonlyPrescription/{commonlyPrescriptionId}")
    public Result delCommonlyPrescription(@PathVariable Long commonlyPrescriptionId){
        prescriptionService.delCommonlyPrescription(commonlyPrescriptionId);
        return Result.success();
    }

    /**
     * 新增常用处方
     * @return
     */
    @PostMapping("/addCommonlyPrescription")
    public Result addCommonlyPrescription(@RequestBody AddCommonlyPrescriptionDTO addCommonlyPrescriptionDTO){
        prescriptionService.addCommonlyPrescription(addCommonlyPrescriptionDTO);
        return Result.success();
    }

    /**
     * 删除常用处方中药品用法用量
     * @param commonlyDosageId
     * @return
     */
    @DeleteMapping("/delCommonlyDosage/{commonlyDosageId}")
    public Result delCommonlyDosage(@PathVariable Long commonlyDosageId){
        prescriptionService.delCommonlyDosage(commonlyDosageId);
        return Result.success();
    }

    /**
     * 编辑常用药品用法用量
     * @param commonlyDosagePO
     * @return
     */
    @PutMapping("/updCommonlyDosage")
    public Result updCommonlyDosage(@RequestBody CommonlyDosagePO commonlyDosagePO){
        prescriptionService.updCommonlyDosage(commonlyDosagePO);
        return Result.success();
    }

    /**
     * 新增常用处方药品
     * @param addCommonlyDosageDTO
     * @return
     */
    @PostMapping("/addCommonlyDosage")
    public Result addCommonlyDosage(@RequestBody AddCommonlyDosageDTO addCommonlyDosageDTO){
        prescriptionService.addCommonlyDosage(addCommonlyDosageDTO);
        return Result.success();
    }


    /**
     * 编辑常用处方
     * @param commonlyPrescriptionPO
     * @return
     */
    @PutMapping("/updateCommonlyPrescription")
    public Result updateCommonlyPrescription(@RequestBody CommonlyPrescriptionPO commonlyPrescriptionPO){
        prescriptionService.updateCommonlyPrescription(commonlyPrescriptionPO);
        return Result.success();
    }
}
